#include "Cell.h"


Cell::Cell()
{
	pos.x = 1;
	pos.y = 1;
	direction.down = new bool;
	direction.left = new bool;
	direction.right = new bool;
	direction.up = new bool;
	*direction.down = *direction.left = *direction.right = *direction.up = FREE;
	direction.num_blocked = 0;
	condition = NOT;
	//cout<<"Constructor empty working"<<endl;
	//cout<<*this<<endl;
}

Cell::Cell(int xxx, int yyy)
{
	setPos(xxx, yyy);
	cout<<"Constructor xxx yyy working"<<endl;
}

Cell::~Cell(void)
{
}


pair<int, int> Cell::getPos()
{
	return make_pair(pos.x, pos.y);
}

void Cell::setPos(int xx, int yy)
{
	pos.x = xx;
	pos.y = yy;
	
}

ostream& operator <<(ostream &stream, Cell p)				//where should it be implemented?
{
	//cout<<"condition: "<<p.condition<<endl;
	//return cout<<p.pos.x<<" "<<p.pos.y<<endl;
	//cout<<"\nOperator <<Cell working"<<endl;
	return stream<<(void *)&p;
}
ostream& operator <<(ostream &stream, Cell *p)
{
	//cout<<"condition: "<<p->condition<<endl;
	//cout<<"\nOperator << *Cell working"<<endl;
	//return cout<<p->pos.x<<" "<<p->pos.y;
	return stream<<(void *)p<<endl;
}




void Cell::setCondition(Condition cond)
{
	condition = cond;
}

void Cell::copyDirection(Direction dir_copy_to, bool *dir_copy_from)
{
	switch (dir_copy_to)
	{
	case UP:
		direction.up = dir_copy_from;
		break;
	case LEFT:
		direction.left = dir_copy_from;
		break;
	}
	//cout<<"Direction bool * is working"<<endl;
}

void Cell::setDirectionToBlocked(int dir_to_set)
{
	switch ((Direction)dir_to_set)
	{
	case UP:
		*direction.up = BLOCKED;
		direction.num_blocked+=UP;
		break;
	case LEFT:
		*direction.left = BLOCKED;
		direction.num_blocked+=LEFT;
		break;
	case RIGHT:
		*direction.right = BLOCKED;
		direction.num_blocked+=RIGHT;
		break;
	case DOWN:
		*direction.down = BLOCKED;
		direction.num_blocked+=DOWN;
		break;
	}
	//cout<<"Direction bool is working"<<endl;
}

int Cell::checkDirectionSwitch(Color clr)		//returns opposite Direction
{
	//switch is meant to be used by black and white cells. white return what to black. black return where to move.
	if (direction.num_blocked != 0)
	{
		switch (direction.num_blocked)
		{
		case UP:
			return DOWN;
		case DOWN:
			return UP;
		case LEFT:
			return RIGHT;
		case RIGHT:
			return LEFT;
		case UP+RIGHT://3
			return DOWN+LEFT;//12
		case DOWN+LEFT://12
			return UP+RIGHT;//3
		case RIGHT+DOWN://6
			return UP+LEFT;//9
		case UP+LEFT://9
			return RIGHT+DOWN;//6
		case UP+DOWN://5
			return LEFT+RIGHT;//10
		case LEFT+RIGHT://10
			return UP+DOWN;//5
		default://SHOULD BE ERRROR!!!!!!!!!!!
			return 1;
		}
	}
	return 0;
}

pair<int, int> decomposite(int val_to_dec)
{
	switch (val_to_dec)
	{
	case UP+DOWN:
		return make_pair(UP, DOWN);
	case LEFT+RIGHT:
		return make_pair(LEFT, RIGHT);
	default:
		return make_pair(1, 1);
	}
	return make_pair(0, 0);
}

Cell::orientation Cell::getDirection()
{
	return direction;
}